<template>
	<view class="page-box">
		<view class="card-box">
			<view class="h1-font">基本信息</view>
			<view style="height: 10rpx;"></view>
			<u-line dashed></u-line>
			<view style="display: flex;padding: 10rpx;border-bottom: 1px solid #c8c9cc;" v-if="!inquiryId">
				<text style="font-size: 30rpx;margin-top: 10rpx;">提现码：</text>
				<u-input v-model="detailId" placeholder="请输入提现码,并点击确定" border="none" @confirm="getDetail(detailId)"></u-input>
			</view>
			<view class="row-box" style="margin-top: 10rpx;">
				<view style="width: 80%;">
				<view class="h2-font">{{detailInfo.modelName}}</view>
				<view>{{detailInfo.specs}}</view>
				<view v-if="detailInfo.iemi">IEMI：{{detailInfo.iemi}}</view>
				<view>{{detailInfo.recycleOrderVo.code}}</view>
				<view>{{detailInfo.createTime}}</view>
			</view>
			<view class="price-box center-box" v-if="detailInfo.recycleOrderVo.price">
				￥{{detailInfo.recycleOrderVo.price}}
			</view>
			</view>
		</view>
		
		<view class="card-box" style="margin-top: 20rpx;" v-if="detailInfo">
			<view class="h1-font">提现信息</view>
			<view style="height: 10rpx;"></view>
			<u-line dashed></u-line>
			<view>
				<u-form label-width="80" :model="form" borderBottom>
					<u-form-item label="提现方式:" prop="type">
						<u-radio-group v-model="form.type" size="20">
							<u-radio :key="1" name="WeChat" active-color="#19be6b">
								<u-icon name="weixin-circle-fill" color="#19be6b" size="20px"></u-icon>
								<span style="color: #19be6b;">微信 </span>
							</u-radio>
							<u-radio :key="2" name="Alipay" activeColor="#2979ff">
								<u-icon name="zhifubao-circle-fill" color="#2979ff" size="20px"></u-icon>
								<span style="color: #2979ff;">支付宝 </span>
							</u-radio>
						</u-radio-group>
					</u-form-item>
					<u-form-item label="姓名:" prop="name">
						<view class="row-box">
							<view style="width: 79%;">
								<u-input v-model="form.name" placeholder="请输入提现的真实姓名"></u-input>
							</view>
						</view>
						
					</u-form-item>
					<u-form-item label="手机号:" prop="code" v-if="form.type === 'Alipay'">
						<view class="row-box">
							<view style="width: 79%;">
								<u-input type="number" v-model="form.code" placeholder="请输入提现的手机号"></u-input>
							</view>
						</view>
						
					</u-form-item>
				</u-form>
			</view>
		</view>
		
		<view style="margin-top: 50rpx;">
			<u-button type="primary" text="确定提现" @click="submit"></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				detailInfo: undefined,
				inquiryId: undefined,
				detailId: undefined,
				form: {
					type: "Alipay", //提现方式 微信=WeChat 支付宝=Alipay
					code: undefined,
					name: undefined,
					id: undefined
				}
			}
		},
		onLoad(params) {
			console.log("获取id", params);
			if(params.id) {
				this.inquiryId = params.id;
				this.getDetail(this.inquiryId);
			}
		},
		methods: {
			submit() {
				if(this.form.type === "WeChat") {
					console.log("微信登录")
					uni.login({
					  provider: 'weixin', //使用微信登录
					  success: (loginRes) => {
					    console.log(loginRes);
						this.form.code = loginRes.code;
						this.submitUrl();
					  }
					});
				}else {
					this.submitUrl()
				}
				
			},
			
			submitUrl() {
				if(!this.form.name){
					uni.showToast({
						title:"姓名为空",
						icon: "error"
					})
					return
				}
				if(!this.form.code) {
					uni.showToast({
						title: "手机号为空",
						icon:"error"
					})
					return
				}
				this.$request("/appCommon/withdraw", "post", this.form).then(() => {
					uni.showToast({
						title: "提现成功！",
						icon: "success"
					})
					
					setTimeout(() => {
						uni.navigateBack()
					}, 2000)
				})
			},
			getDetail(id) {
				this.$request("/appShopApi/order/queryInquiryOrderDetail", 'get', {inquiryOrderId: id}).then(res => {
					this.detailInfo = res.data;
					if(this.detailInfo.recycleOrderVo.customerWithdraw){
						this.form.id = this.detailInfo.recycleOrderVo.customerWithdraw.id;
					}
					this.detailInfo.specs = this.detailInfo.specs.replaceAll(",", " ")
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.page-box {
		padding: 20rpx;
	}
	.card-box {
		background-color: #fff;
		padding: 20rpx;
		box-shadow: 0 1px 3px #c8c9cc;
		border-radius: 10rpx;
		font-size: 28rpx;
		color: #303133;
		line-height: 60rpx;
	}
	.price-box {
		font-size: 38rpx;
		font-weight: 900;
		color: #fa3534;
	}
</style>
